//
//  UserPointCell.swift
//  koolcar
//
//  Created by xiantian on 2023/11/1.
//

import UIKit
 

class UserPointCell: UITableViewCell {
    var titleLab: UILabel!
    var createTimeLab: UILabel!
    var pointLab: UILabel!
    var lineView: UIView!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
 
        titleLab = UILabel()
        titleLab.textColor = Theme.titleLabColor
        titleLab.backgroundColor = UIColor.clear
        titleLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 14)
        titleLab.numberOfLines = 0
        titleLab.lineBreakMode = .byTruncatingTail
        titleLab.textAlignment = .left
        contentView.addSubview(titleLab)
        
        createTimeLab = UILabel()
        createTimeLab.textColor = Theme.titleLabColor
        createTimeLab.backgroundColor = UIColor.clear
        createTimeLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 12)
        createTimeLab.numberOfLines = 0
        createTimeLab.lineBreakMode = .byTruncatingTail
        createTimeLab.textAlignment = .left
        contentView.addSubview(createTimeLab)
        
        pointLab = UILabel()
        pointLab.textColor = Theme.titleLabColor
        pointLab.backgroundColor = UIColor.clear
        pointLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 12)
        pointLab.numberOfLines = 1
        pointLab.lineBreakMode = .byTruncatingTail
        pointLab.textAlignment = .right
        contentView.addSubview(pointLab)
        
        lineView = UIView()
        lineView.backgroundColor = Theme.lineColor
        contentView.addSubview(lineView)
        
//        titleLab.text  = "线下消费"
//        createTimeLab.text  = "2023-06-02 09：08：25"
//        pointLab.text = "+20000"
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(10)
            make.height.greaterThanOrEqualTo(20)
        }
        
        createTimeLab.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.top.equalTo(titleLab.snp.bottom).offset(4)
            make.right.equalTo(-10)
        }
        
        pointLab.snp.makeConstraints { make in
            make.left.equalTo(titleLab.snp.right).offset(10)
            make.top.equalTo(10)
            make.right.equalTo(-10)
            make.height.equalTo(22)
        }
        
        lineView.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.top.equalTo(createTimeLab.snp.bottom).offset(10)
            make.height.equalTo(0.5)
            make.bottom.equalTo(-0.5)
        }
    }
    
    func setUserPointCell(data: IntegralContentModel) {
        titleLab.text  = data.type ?? ""
        createTimeLab.text  = data.createdTime ?? ""
        pointLab.text = String(format: "%.0f", data.integralValue ?? 0)
        self.updateConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
